*******************************************************************************
*** Replication Material - "The Colonial Roots of Structural Coup-Proofing" ***
***                Marius Mehrl and Ioannis Choulis, 4.1.2021               ***
*******************************************************************************
use "C:\~\Replication Data\ColonialRoots_Counterbalancing_ReplicationData.dta", clear

xtset ccode year

*****************
* Main Analysis *
*****************

* Table 1
logit bin_counterb_DB i.colony_France_CoW c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
estat ic
margins, dydx(colony_France) level(95) post
estimates store one

logit bin_counterb_DB i.colony_France_CoW colonialized c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
estat ic

logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
estat ic
margins, dydx(colony_France) level(95) post
estimates store two

xtlogit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
margins, dydx(colony_France) level(95) post predict(pu0)
estimates store three

logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
estat ic

* Figure 1 (uses stored results computed in code for Table 1)
coefplot (one, label(Model One)) (two, label(Model Three)) (three, label(Model Four)), xline(0) scheme(plotplain)  xtitle("Change in Counterbalancing") title("French Colonialism: First Difference Estimates") aspectratio(1) yscale(noline) ylabel("")

* Illustrative Example: Cote d'Ivoire
sum bin_counterb_DB colony_France_CoW Colonialism_direct COLY RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal timesincecb if countries_gwid==437 & year==1960
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
margins, at(colony_France_CoW==1 Colonialism_direct==1 COLY==121 RegimeT==0 ln_milex==7.600903  coup_prev10y==0 ln_rgdp==8.472679  ln_pop==8.152443 gwf_personal==0 timesincecb==0)
margins, at(colony_France_CoW==0 Colonialism_direct==1 COLY==121 RegimeT==0 ln_milex==7.600903  coup_prev10y==0 ln_rgdp==8.472679  ln_pop==8.152443 gwf_personal==0 timesincecb==0)

*******************************************************************************************
* Additional Analyses & Robustness Checks reported in Appendix & Figures 2-3 in main paper*
*******************************************************************************************

* Section A.1.	Descriptive statistics (Table A1)
sum  bin_counterb_DB colony_France_CoW colonialized Colonialism_direct COLY RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal colony_UK_CoW colony_Portugal_CoW colony_Spain_CoW colony_Russia_CoW colony_Ottoman_CoW ///
levelofpoliticaltransformatio levelofeconomictransformation levelofsocialtransformation years_since_indep tradewfrance log_effectnum_pb MID_bin MID_incid_5yav couprisk regcb_DBdummy army_centrality armedconf_prev10y ///
ln_egippop democ milreg ln_milex_persoldier unmatchedofficercorps cbcount coup_x 

* Section A.2.	Model run on a matched sample (Table A2)
gen compl_obs=0
replace compl_obs=1 if bin_counterb_DB!=. & colony_UK_CoW!=. & colony_France_CoW!=. & colonialized!=. & RegimeT!=. & ln_milex!=. & coup_prev10y!=. & ln_rgdp!=. & ln_pop!=. & gwf_personal!=.
imb colonialized RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if compl_obs==1, treatment(colony_France_CoW)
cem colonialized RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if compl_obs==1, treatment(colony_France_CoW)
logit bin_counterb_DB colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb [iweight=cem_weights], vce(cluster ccode) difficult
margins, dydx(colony_France) level(95) post
estimates store match

* Section A.3.	Models run on cross-sectional samples
* Construct cross-sectional versions of dependent and independent variables
gen  bin_counterb_nots=.
replace bin_counterb_nots=bin_counterb_DB if l.bin_counterb_DB==.& year<1976
by ccode: egen min_cb=min(bin_counterb_DB)
by ccode: egen max_cb=max(bin_counterb_DB)
by ccode: egen mean_cb=mean(bin_counterb_DB)
by ccode: egen mean_polity=mean(polity2)
by ccode: egen mean_milex=mean(ln_milex)
by ccode: egen sum_coups=sum(coup_x)
by ccode: egen mean_gdp=mean(ln_rgdp)
by ccode: egen mean_pop=mean(ln_pop)
by ccode: egen mean_personalist=mean(gwf_personal)
gen crossection=0 if bin_counterb_DB!=.
replace crossection=1 if year==2005 & bin_counterb_DB!=.

sum bin_counterb_nots 
sum min_cb max_cb mean_cb if crossection==1

* Estimate cross-sectional models (Table A3)
logit bin_counterb_nots colony_France_CoW colonialized ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal 
margins, dydx(colony_France) level(90) post
estimates store cs1

logit min_cb colony_France_CoW colonialized mean_milex sum_coups mean_gdp mean_pop mean_personalist if crossection==1
margins, dydx(colony_France) level(90) post
estimates store cs2

logit max_cb colony_France_CoW colonialized mean_milex sum_coups mean_gdp mean_pop mean_personalist if crossection==1
margins, dydx(colony_France) level(90) post
estimates store cs3

fracreg logit mean_cb colony_France_CoW colonialized mean_milex sum_coups mean_gdp mean_pop mean_personalist if crossection==1
margins, dydx(colony_France) level(90) post
estimates store cs4

* Figure 2 (uses stored results computed in code for A2 and A3)
coefplot (match, label(Matched Sample)) (cs1, label(CB (First Observation))) (cs2, label(CB (Max.))) (cs3, label(CB (Min.))) (cs4, label(CB (Mean))) ///
, xline(0) scheme(plotplain)  xtitle("Change in Counterbalancing") title("French Colonialism: First Difference Estimates") aspectratio(1) ///
yscale(noline) ylabel("") levels(90)  

* Section A.4.	Over-time variation in the effect of French colonialism
gen yearbla = year-1960

* Model A6 and left panel of figure 3 (Table A4)
logit bin_counterb_DB i.colony_France_CoW##c.yearbla##c.yearbla##c.yearbla i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if colonialized==1, vce(cluster ccode)
margins, dydx(colony_France_CoW) at(yearbla=(0(1)50)) level(90)
marginsplot, yline(0) scheme(plotplain) aspect(1) xtitle("Year") title("") ytitle("Change in Counterbalancing") /// 
xlabel(0 "1960" 10 "1970" 20 "1980" 30 "1990" 40 "2000" 50 "2010") name(timevar, replace)

* Models A7-A12 and right panel of figure 3 (Table A5)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if year==1960, vce(cluster ccode)
margins, dydx(colony_France_CoW) level(90) post
estimates store decade_cs1
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if year==1970, vce(cluster ccode)
margins, dydx(colony_France_CoW) level(90) post
estimates store decade_cs2
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if year==1980, vce(cluster ccode)
margins, dydx(colony_France_CoW) level(90) post
estimates store decade_cs3
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if year==1990, vce(cluster ccode)
margins, dydx(colony_France_CoW) level(90) post
estimates store decade_cs4
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if year==2000, vce(cluster ccode)
margins, dydx(colony_France_CoW) level(90) post
estimates store decade_cs5
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if year==2010, vce(cluster ccode)
margins, dydx(colony_France_CoW) level(90) post
estimates store decade_cs6
coefplot (decade_cs1, mlabel("1960") mlabpos(4)) (decade_cs2, mlabel("1970") mlabpos(4)) (decade_cs3, mlabel("1980") mlabpos(4)) (decade_cs4, mlabel("1990") mlabpos(4)) ///
(decade_cs5, mlabel("2000") mlabpos(4)) (decade_cs6, mlabel("2010") mlabpos(4)), xline(0) scheme(plotplain)  xtitle("Change in Counterbalancing") ///
title(" ") aspectratio(1) yscale(noline) ylabel("") levels(90) name(decades, replace) legend(off)  

* Combine panels to make figure 3
graph combine decades timevar, ycommon scheme(plotplain) title("French Colonialism: Time-varying Effects")  

* Models A13-A15 and figure A1 (Table A6)
logit bin_counterb_DB i.colony_France_CoW##c.years_since_indep##c.years_since_indep##c.years_since_indep colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
margins, dydx(colony_France_CoW) at(years_since_indep=(0(1)60)) level(90) 
marginsplot, yline(0) scheme(plotplain) name(interact1, replace) aspect(1) xtitle("Years since Independence") title("") ytitle("Change Pr.(Counterbalancing)")
logit bin_counterb_DB i.colony_France_CoW##c.years_since_indep##c.years_since_indep##c.years_since_indep colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if years_since_indep<=60, vce(cluster ccode)
margins, dydx(colony_France_CoW) at(years_since_indep=(0(1)60)) level(90)
marginsplot, yline(0) scheme(plotplain) name(interact2, replace) aspect(1) xtitle("Years since Independence") title("") ytitle("Change Pr.(Counterbalancing)")
logit bin_counterb_DB i.colony_France_CoW##c.years_since_indep##c.years_since_indep##c.years_since_indep colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if years_since_indep<=50, vce(cluster ccode)
margins, dydx(colony_France_CoW) at(years_since_indep=(0(1)50)) level(90)
marginsplot, yline(0) scheme(plotplain) name(interact3, replace) aspect(1) xtitle("Years since Independence") title("") ytitle("Change Pr.(Counterbalancing)")
graph combine interact1 interact2 interact3, ycommon rows(1) iscale(*.6) scheme(plotplain)

* Section A.5.	Models with additional colonial rule control variables I (Table A7)
logit bin_counterb_DB colony_France_CoW colony_UK_CoW c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB colony_France_CoW colony_UK_CoW i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB colony_France_CoW colony_UK_CoW colony_Portugal_CoW colony_Spain_CoW colony_Russia_CoW colony_Ottoman_CoW c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB colony_France_CoW colony_UK_CoW colony_Portugal_CoW colony_Spain_CoW colony_Russia_CoW colony_Ottoman_CoW i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB colony_France_CoW levelofpoliticaltransformatio levelofeconomictransformation levelofsocialtransformation  c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB colony_France_CoW levelofpoliticaltransformatio levelofeconomictransformation levelofsocialtransformation i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* Section A.6.	Models with additional colonial rule control variables II (Table A8)
logit bin_counterb_DB i.colony_France_CoW years_since_indep colonialized  c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW years_since_indep colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal  c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW tradewfrance colonialized  c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW tradewfrance colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal  c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* Section A.7.	British colonialism and counterbalancing
* (Table A9)
logit bin_counterb_DB i.colony_UK_CoW c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_UK_CoW colonialized c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_UK_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
xtlogit bin_counterb_DB i.colony_UK_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_UK_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* (Table A10)
logit bin_counterb_DB i.colony_UK_CoW c.timesincecb##c.timesincecb##c.timesincecb if colonialized==1, vce(cluster ccode)
logit bin_counterb_DB i.colony_UK_CoW i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if colonialized==1, vce(cluster ccode)
xtlogit bin_counterb_DB i.colony_UK_CoW i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if colonialized==1, vce(cluster ccode)
logit bin_counterb_DB i.colony_UK_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if colonialized==1, vce(cluster ccode)

* Section A.8.	Restricting the sample to former colonies
* (Table A11)
logit bin_counterb_DB i.colony_France_CoW c.timesincecb##c.timesincecb##c.timesincecb if colonialized==1, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if colonialized==1, vce(cluster ccode)
xtlogit bin_counterb_DB i.colony_France_CoW i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if colonialized==1, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if colonialized==1, vce(cluster ccode)

* (Table A12)
logit bin_counterb_DB i.colony_France_CoW i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* Section A.9.	Alternative dependent variable: Pilster & Böhmelt counterbalancing
* (Table A13)
xtgls log_effectnum_pb i.colony_France_CoW, panels(heteroskedastic) corr(psar1) force
xtgls log_effectnum_pb i.colony_France_CoW colonialized, panels(heteroskedastic) corr(psar1) force
xtgls log_effectnum_pb i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal, panels(heteroskedastic) corr(psar1) force
xtreg log_effectnum_pb i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal, re vce(cluster ccode)
xtgls log_effectnum_pb i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal, panels(heteroskedastic) corr(psar1) force

* (Table A14)
gen DB_missing=0 if bin_counterb_DB!=.
replace DB_missing=1 if bin_counterb_DB==.
xtgls log_effectnum_pb i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if DB_missing==0, panels(heteroskedastic) corr(psar1) force
xtgls log_effectnum_pb i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if DB_missing==1, panels(heteroskedastic) corr(psar1) force
xtreg log_effectnum_pb i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if DB_missing==0, re vce(cluster ccode)
xtreg log_effectnum_pb i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal if DB_missing==1, re vce(cluster ccode)

* Section A.10.	Models with additional present-day control variables I (Table A15)
logit bin_counterb_DB  i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal MID_bin c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal MID_bin c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal MID_incid_5yav c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal MID_incid_5yav c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* Section A.11.	Models with additional present-day control variables II (Table A16)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex couprisk ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex couprisk ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal regcb_DBdummy c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal regcb_DBdummy c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* Section A.12.	Models with additional present-day control variables III (Table A17)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal army_centrality c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal army_centrality c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal armedconf_prev10y c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal armedconf_prev10y c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* Section A.13.	Models with additional present-day control variables IV (Table A18)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal ln_egippop c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal ln_egippop c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal i.region c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal i.region c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* Section A.14.	Models with additional present-day control variables V (Table A19)
logit bin_counterb_DB i.colony_France_CoW colonialized democ ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY democ ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal milreg c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal milreg c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex_persoldier coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex_persoldier coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* Section A.15.	Models with unmatched officer corps as additional control variable  (Table A20)
logit bin_counterb_nots i.colony_France_CoW unmatchedofficercorps
logit bin_counterb_DB i.colony_France_CoW unmatchedofficercorps i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
logit bin_counterb_DB i.colony_France_CoW unmatchedofficercorps i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)

* Section A.16.	Alternative dependent variable: Number of counterbalancing organizations (Table A21)
poisson cbcount i.colony_France_CoW l.cbcount if cbcount<6, vce(cluster ccode)
poisson cbcount i.colony_France_CoW colonialized l.cbcount if cbcount<6, vce(cluster ccode)
poisson cbcount i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal l.cbcount if cbcount<6, vce(cluster ccode)
poisson cbcount i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal l.cbcount if cbcount<6, vce(cluster ccode)
 
* Section A.17.	4-Fold Cross-Validation Exercise  (Table A22)
* Full Model
forvalues h=1/10 {
preserve
quietly logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
predict fitted, pr
quietly roctab bin_counterb_DB fitted
xtile group=uniform(), nq(4)
generate cv_fitted=.
forvalues i=1/4 {
quietly logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb if group~=`i', vce(cluster ccode) 
quietly predict cv_fittedi, pr
quietly replace cv_fitted=cv_fittedi if group==`i'
quietly drop cv_fittedi
}
roctab bin_counterb_DB cv_fitted
capture drop fitted group1 cv_fitted
restore
}
* Drop Colonial Dummy
forvalues h=1/10 {
preserve
quietly logit bin_counterb_DB i.colony_France_CoW colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
keep if e(sample)
quietly logit bin_counterb_DB colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb, vce(cluster ccode)
predict fitted, pr
quietly roctab bin_counterb_DB fitted
xtile group=uniform(), nq(4)
generate cv_fitted=.
forvalues i=1/4 {
quietly logit bin_counterb_DB colonialized i.RegimeT ln_milex coup_prev10y ln_rgdp ln_pop gwf_personal c.timesincecb##c.timesincecb##c.timesincecb  if group~=`i', vce(cluster ccode)
quietly predict cv_fittedi, pr
quietly replace cv_fitted=cv_fittedi if group==`i'
quietly drop cv_fittedi
}
roctab bin_counterb_DB cv_fitted
capture drop fitted group cv_fitted
restore
}

* Section A.18.	Alternative dependent variable: Coup attempts  (Table A23)
btscs coup_x year ccode, gen(timesincecoup)

logit coup_x i.colony_France_CoW colonialized i.RegimeT ln_milex ln_rgdp ln_pop gwf_personal c.timesincecoup##c.timesincecoup##c.timesincecoup if bin_counterb_DB!=., vce(cluster ccode)
logit coup_x i.colony_France_CoW bin_counterb_DB colonialized i.RegimeT ln_milex ln_rgdp ln_pop gwf_personal c.timesincecoup##c.timesincecoup##c.timesincecoup if bin_counterb_DB!=., vce(cluster ccode)
logit coup_x i.colony_France_CoW i.Colonialism_direct COLY i.RegimeT ln_milex ln_rgdp ln_pop gwf_personal c.timesincecoup##c.timesincecoup##c.timesincecoup if bin_counterb_DB!=., vce(cluster ccode)
logit coup_x i.colony_France_CoW bin_counterb_DB i.Colonialism_direct COLY i.RegimeT ln_milex ln_rgdp ln_pop gwf_personal c.timesincecoup##c.timesincecoup##c.timesincecoup if bin_counterb_DB!=., vce(cluster ccode)
